package org.iWMS.core.log;

import org.apache.log4j.Logger;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;

import java.lang.reflect.Method;

/**
 * Created with IntelliJ IDEA.
 * User: issuser
 * Date: 13-6-25
 * Time: 下午3:53
 * To change this template use File | Settings | File Templates.
 */
@Aspect
public class LogAspect {

    private final static Logger logger=Logger.getLogger(LogAspect.class);

    @Before("@annotation(org.iWMS.core.log.LogRecord)")
    private void doSystemLog(JoinPoint jp) {
        Method method = ((MethodSignature)jp.getSignature()).getMethod();
        LogRecord annotation = method.getAnnotation(LogRecord.class);
        String methodDescp = annotation.description();
        logger.info("Class:" + jp.getTarget().getClass().getName() + " Method:" + method.getName() + " Description:" + methodDescp);
    }
}
